<?php
/*
* Author: Nguyen Hai Nam
* Module: News
* Desc	: Something news hot
* Date	: 24/06/2012
*/
class NewsModule extends Pick_Core_Module{
	
	function NewsModule(){
		
		parent::Pick_Core_Module();
		//$this->pushJS();
		//$this->pushCSS();
		# Languages
		$languages = new Pick_Core_Languages();
		$objectLanguages = "";
		$objectLanguages = $languages->getObjects(1, 'status = 1', array('position'=>'ASC'), '');
		if($objectLanguages){
			$objectLanguages = $objectLanguages['data'];	
		}#endif
		$this->template->assign("objectLanguages", $objectLanguages);
	}
	public function getContent(){

		$newscategory 	= new Pick_Dao_NewsCategory();
		$news = new Pick_Dao_News();
		$url = new Pick_Http_Url();
		$id = $this->request->get('id');

		if($id){
			$page = $this->request->get('p');
			$objCat = $newscategory->getObject($id);
			$strUrl = "";
			if(is_object($objCat)){
				$strUrl = $url->getUrl('news', $id, $objCat->getField('slug'));
			}
			$breadcrumb = $newscategory->getPathParrent($id);
			$productcategorysub = new Pick_Dao_ProductCategorySub();
			$strIdSubCategory = implode(",",$newscategory->getIdSubCategory($id,1));
			$arrObjNews = "";
			if($strIdSubCategory!="")
				$arrObjNews = $productcategorysub->getObjectProductsNews($page, "categoryid IN($strIdSubCategory)", array('productid'=>'DESC'), 10);
			$this->template->assign("arrObjNews", $arrObjNews);
			$this->template->assign("breadcrumb", $breadcrumb);
			$this->template->assign("objCat", $objCat);
			$this->template->assign("strUrl", $strUrl);
			
			return $this->display('newssub');
			
		}else{
			$arrObjNewsCategory = $newscategory->getObjects(1, "cid=0 AND home=1 AND status=1", array('position'=>'DESC'), "");
			$this->template->assign("arrObjNewsCategory", $arrObjNewsCategory['data']);
			$this->template->assign("newscategory", $newscategory);
			$this->template->assign("news", $news);
			return $this->display('news');	
		}
	}
}